<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'center',border:false">
    	<!-- Begin of toolbar -->
        <div id="menu-toolbar">
            <div class="menu-toolbar-button">
                <a href="#" class="easyui-linkbutton" iconCls="icon-add" onclick="openAdd()" plain="true">添加</a>
                <a href="#" class="easyui-linkbutton" iconCls="icon-edit" onclick="openEdit()" plain="true">修改</a>
                <a href="#" class="easyui-linkbutton" iconCls="icon-remove" onclick="del()" plain="true">删除</a>
                <a href="#" class="easyui-linkbutton" iconCls="icon-reload" onclick="reload()" plain="true">刷新</a>
            </div>
            <div class="menu-toolbar-search">
                <label>库存类型：</label>
                <select class="easyui-combobox" panelHeight="auto" style="width:130px" editable='false' >
                		<option value="0">全部</option>
                    <#if baseInfo?? >
                    	<#list baseInfo as info>
                    		<option value="${info.id!}">${info.paramName!}</option>
                    	</#list>
                    </#if>
                </select>
                <label>产品/物料名称：</label><input class="wu-text" style="width:100px">
                <a href="#" class="easyui-linkbutton" iconCls="icon-search">查询</a>
            </div>
        </div>
        <!-- End of toolbar -->
        <table id="menu-datagrid" toolbar="#menu-toolbar"></table>
    </div>
</div>
<!-- Begin of easyui-dialog -->
<div id="add-dialog" class="easyui-dialog" data-options="closed:true,iconCls:'icon-save'" style="width:400px; padding:10px;">
	<form id="add-form" method="post">
        <table>
        	<tr>
                <td><input type="hidden" name="id" class="wu-text" /></td>
            </tr>
            <tr>
                <td width="60" align="right">菜单名称:</td>
                <td><input type="text" name="menuName" class="wu-text" /></td>
            </tr>
            <tr>
                <td align="right">链接:</td>
                <td><input type="text" name="url" class="wu-text" /></td>
            </tr>
            <tr>
                <td align="right">图标:</td>
                <td><input type="text" name="icon" class="wu-text" /></td>
            </tr>
            <tr>
                <td align="right">菜单级别:</td>
                <td>
	                <select name="parentId" class="easyui-combobox" panelHeight="auto" style="width:270px">
	                    <option value='0'>无</option>
	                    <#if menus?? >
							<#list menus as menu>
					           <option  value="${menu.id!}">${menu.menuName!}</option>
					    	</#list>
						</#if>
	                </select>
                </td>
            </tr>
        </table>
    </form>
</div>
<!-- End of easyui-dialog -->
<script type="text/javascript">

	/**
	*刷新datagrid
	*/
	function reload() {
		$('#menu-datagrid').datagrid('reload');  
	}
	/**
	* Name 添加记录
	*/

	function add(){
		$('#add-form').form('submit', {
			url:'system/menu/saveorupdate',
			success:function(data){
				if(data){
					$.messager.alert('信息提示','提交成功！','info');
					$('#add-dialog').dialog('close');
					reload();
				}
				else
				{
					$.messager.alert('信息提示','提交失败！','info');
				}
			}
		});
	}
	
	/**
	* Name 修改记录
	*/
	function edit(){
		$('#add-form').form('submit', {
			url:'system/menu/saveorupdate',
			success:function(data){
				if(data){
					$.messager.alert('信息提示','提交成功！','info');
					$('#add-dialog').dialog('close');
					reload();
				}
				else
				{
					$.messager.alert('信息提示','提交失败！','info');
				}
			}
		});
	}
	
	/**
	* Name 删除记录
	*/
	function del(){
		var items = $('#menu-datagrid').datagrid('getSelections');
		var ids = new Array();
		$(items).each(function(){
			ids.push(this.id);	
		});
		if(ids.length<=0) {
			$.messager.alert('信息提示','请选择要删除的选项','info');
			return;
		}
		$.messager.confirm('信息提示','确定要删除该记录？', function(result){
			if(result){
				//alert(ids);return;
				$.ajax({
					url:'system/menu/delete',
					dataType:'json',
					data:{'ids':ids},
					traditional:true,
					success:function(data){
						if(data){
							$.messager.alert('信息提示','删除成功！','info');		
							reload();
						}
						else
						{
							$.messager.alert('信息提示','删除失败！','info');		
						}
					}	
				});
			}	
		});
	}
	
	/**
	* Name 打开添加窗口
	*/
	function openAdd(){
		$('#add-form').form('clear');
		$('#add-dialog').dialog({
			closed: false,
			modal:true,
            title: "添加信息",
            buttons: [{
                text: '确定',
                iconCls: 'icon-ok',
                handler: add
            }, {
                text: '取消',
                iconCls: 'icon-cancel',
                handler: function () {
                    $('#add-dialog').dialog('close');                    
                }
            }]
        });
	}
	
	/**
	* Name 打开修改窗口
	*/
	function openEdit(){
		$('#add-form').form('clear');
		var item = $('#menu-datagrid').datagrid('getSelected');
		if(item==null||item==undefined) {
			$.messager.alert('信息提示','请选择你要修改的信息！','info');	
			return;
		}
		//alert(item.productid);return;
		$.ajax({
			url:'system/menu/edit',
			dataType:'json',
			data:{'id':item.id},
			success:function(data){
				console.log(data);
				if(!data){
					$('#add-dialog').dialog('close');	
				}
				else{
					//绑定值
					$('#add-form').form('load', data);
				}
			}	
		});
		$('#add-dialog').dialog({
			closed: false,
			modal:true,
            title: "修改信息",
            buttons: [{
                text: '确定',
                iconCls: 'icon-ok',
                handler: edit
            }, {
                text: '取消',
                iconCls: 'icon-cancel',
                handler: function () {
                    $('#add-dialog').dialog('close');                    
                }
            }]
        });
	}	
	
	/**
	* Name 分页过滤器
	*/
	function pagerFilter(data){            
		if (typeof data.length == 'number' && typeof data.splice == 'function'){// is array                
			data = {                   
				total: data.length,                   
				rows: data               
			}            
		}        
		var dg = $(this);         
		var opts = dg.datagrid('options');          
		var pager = dg.datagrid('getPager');          
		pager.pagination({                
			onSelectPage:function(pageNum, pageSize){                 
				opts.pageNumber = pageNum;                   
				opts.pageSize = pageSize;                
				pager.pagination('refresh',{pageNumber:pageNum,pageSize:pageSize});                  
				dg.datagrid('loadData',data);                
			}          
		});           
		if (!data.originalRows){               
			data.originalRows = (data.rows);       
		}         
		var start = (opts.pageNumber-1)*parseInt(opts.pageSize);          
		var end = start + parseInt(opts.pageSize);        
		data.rows = (data.originalRows.slice(start, end));         
		return data;       
	}
	
	/**
	* Name 载入数据
	*/
	$('#menu-datagrid').datagrid({
		url:'system/alert/getdata',
		loadFilter:pagerFilter,		
		rownumbers:true,
		singleSelect:false,
		pageSize:20,           
		pagination:true,
		multiSort:true,
		fitColumns:true,
		fit:true,
		columns:[[
			{ checkbox:true},
			{ field:'id',title:'预警编号',hidden:true,width:100,sortable:true},
			{ field:'menuName',title:'预警物料/产品名称',width:100,sortable:true},
			{ field:'icon',title:'所属类别',width:100,sortable:true},
			{ field:'url',title:'限额预警',width:180,sortable:true},
			{ field:'level',title:'保质期预警',width:100},
			
		]]
	});
</script>